package com.trivera.adhoc;

import java.util.*;

public class Company extends TaxableEntity {
	public static final String COMPANY_TAXID_REGEX = "^\\d\\d-\\d{7}$";

	private Collection<Payable> resources;

	public Company(String name, String taxId) {
		super(name, taxId);

		
		// java 8 new TreeSet<>((x,y) -> x.getName().compareTo(y.getName())
		
		resources = new TreeSet<>(new Comparator<Payable>() {
			@Override
			public int compare(Payable arg0, Payable arg1) {
				return arg0.getName().compareTo(arg1.getName());
			}
		});
	}

	@Override
	public void hire(Payable newhire) {
		resources.add(newhire);
	}

	@Override
	protected String getTaxIdRegex() {
		return COMPANY_TAXID_REGEX;
	}

	@Override
	public float pay(float amount) {
		System.out.println("Paying Company " + getName());
		float total = 0;
		Iterator<Payable> it = resources.iterator();
		while (it.hasNext())
			total += it.next().pay(amount);

		return total;
	}

}
